package com.ajx.todo.study;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ajx.todo.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by lai on 2017/9/9.
 */

public class StudyFragment extends Fragment{

    private RecyclerView rvExampleList;
    private List<String> studies =new ArrayList<>();
    private ExampleAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View inflate = inflater.inflate(R.layout.frag_example, container, false);
        rvExampleList = ((RecyclerView) inflate.findViewById(R.id.rv_example_list));
        rvExampleList .setLayoutManager(new LinearLayoutManager(getActivity()));
        adapter = new ExampleAdapter(studies);
        rvExampleList.setAdapter(adapter);
        return inflate;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        studies.clear();
        studies.add("架构");
        studies.add("设计模式");
        studies.add("自定义 VIEW");
        adapter.notifyDataSetChanged();
    }

    class ExampleAdapter extends BaseQuickAdapter<String,BaseViewHolder>{
        public ExampleAdapter(@Nullable List<String> data) {
            super(R.layout.item_example_title,data);
        }

        @Override
        protected void convert(BaseViewHolder helper, String item) {
            helper.setText(R.id.tv_example_title,item);
        }
    }
}
